@echo off
mkdir logs\%db2_server_name%

set logfile=logs\%db2_server_name%\%2.log

db2 describe table %1.%2 show detail >%logfile%

echo  -----------------------------------------Below is (are) pk-------------------------  >>%logfile%
db2 -x "select LTRIM(RTRIM(sp.column_name))||' '|| LTRIM(RTRIM(co.TYPENAME)) || '(' || LTRIM(RTRIM(CHAR(co.LENGTH))) || ')',sp.table_schem from sysibm.sqlprimarykeys sp, SYSCAT.COLUMNS co where sp.table_name=upper('%2') and sp.table_name=co.TABNAME and sp.column_name = co.COLNAME" >>%logfile%

echo  -----------------------------------------Below is (are) Fk-------------------------  >>%logfile%

db2 -x "select LTRIM(RTRIM(PKTABLE_SCHEM))||'.'||LTRIM(RTRIM(PKTABLE_NAME))||'.'||LTRIM(RTRIM(PKCOLUMN_NAME))|| '-->'||LTRIM(RTRIM(FKTABLE_SCHEM))|| '.'||LTRIM(RTRIM(FKTABLE_NAME))||'.'||LTRIM(RTRIM(FKCOLUMN_NAME)) from sysibm.SQLFOREIGNKEYS where (PKTABLE_SCHEM=upper('%1') and PKTABLE_NAME =upper('%2')) or (FKTABLE_SCHEM=upper('%1') and FKTABLE_NAME =upper('%2'))" >>%logfile%









echo ------------------------------------------Below is(are) index---------------------------------------- >>%logfile%
db2 -x select VARCHAR(INDNAME,30), VARCHAR(TABNAME,30) , VARCHAR(COLNAMES,130) from SYSCAT.INDEXES where TABSCHEMA = upper('%1') AND TABNAME = upper('%2')  >>%logfile%

echo  -----------------------------------------Below are the first 20 rows in the %1.%2 table---------  >>%logfile%
db2  select * from %1.%2 fetch first 20 rows only >>%logfile%

echo  ------------------------------------------Below is the sql of the %1.%2 view ---------  >>%logfile%
db2 -x select varchar(text,32670)  from syscat.views where viewschema=upper('%1')and viewname = upper('%2') >>%logfile%

echo -------------------------------------------Get tables in a view ---------------------  >>%logfile%
db2 -x select distinct bname from syscat.viewdep where viewname=upper('%2')  and btype='T' >>%logfile%
start  %logfile%
